/**
	Copyright (c) 2010 ATTi 
	All rights reserved.
	Author: Michael Shu
	Date: 2/25/2010
	Depreciated since s142 on 6/17/2011
*/

global class scheduleSendEmail /*implements Schedulable */{
	/* To schedule it every 30 mins, in Anonymous Blocks and execute below commands
	   scheduleSendEmail c0 = new scheduleSendEmail();
	   String sch0 = scheduleSendEmail.CRON_EXP0;
	   System.schedule('Schedule Send Email Job0', sch0, c0);
	
	   scheduleSendEmail c1 = new scheduleSendEmail();
	   String sch1 = scheduleSendEmail.CRON_EXP30;
	   System.schedule('Schedule Send Email Job1', sch1, c1);
	*/
/*	
	public static String CRON_EXP0  = '0 00 * * * ?';
	public static String CRON_EXP30 = '0 30 * * * ?';
	public static Integer LIMITED = 200;
	global void execute (SchedulableContext SC){	
		execute();
	}
	
	public static List<Sobject> start(){
		DateTime aFewMinutesAgo = DateTime.now().addMinutes(-3);
		String IOGIncidentRecordTypeID =RecordTypeHelper.GetRecordTypeID('Case',  'IOG Incident');
		
        string query = 'Select Id From Case Where isEmailNotificationSent__c = false and RecordTypeId = \'' + IOGIncidentRecordTypeID + '\' and Origin = \'CRF\' and RVP_Region2__c = \'In-Region West\' and CreatedDate < :aFewMinutesAgo limit ' + LIMITED + ' ';
		
        return Database.query(query);		
	}
	
	public static void execute(){
		List<Sobject> scope = start();
		Set<ID> parentIDs = new Set<ID>();
		for(Sobject s : scope){
			Case c = (Case) s;
			parentIDs.add(c.Id);
			c.isEmailNotificationSent__c = true;
		}
		System.debug('parentIDs.isEmpty() = ' + parentIDs.isEmpty());
		if(!parentIDs.isEmpty()){
			Savepoint sp = Database.setSavepoint(); 
			try{
				Boolean sendEmail_result = CaseIOGClass.sendEmailtoIOGWest(parentIDs);
				update scope;
			}catch(Exception ex){
				System.debug('update scope Fail : ' + ex);
				Database.rollback(sp); 
				mailAnyExceptionToMe('update scope Fail', ex);
			}	
		}
	}
	
	private static void mailAnyExceptionToMe(String subject, Exception e){
		Messaging.SingleEmailMessage mail =new Messaging.SingleEmailMessage();
	    String[] toAddresses = new String[] {'SalesforceDev@attinteractive.com'};
	    mail.setToAddresses(toAddresses);
	    mail.setReplyTo('SalesforceDev@attinteractive.com');
	    mail.setSenderDisplayName('Apex error message');
	    mail.setSubject('scheduleSendEmail :' + subject + ' User Name : ' + UserInfo.getUserName());
	    mail.setPlainTextBody(e.getMessage());
	    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });		
	}
*/
}